﻿Imports System.Web.UI.WebControls
Imports Microsoft.IdentityManagement.WebUI.Controls

Public Class UIUtils

    Public ActivitySettingsPart As ActivitySettingsPart

    Public Function CreateCheckBox(ByVal label As String, ByVal ID As String, ByVal defaultValue As Boolean)

        Dim row As New TableRow
        Dim cell1 As New TableCell
        Dim cell2 As New TableCell
        Dim label1 As New Label
        Dim checkbox As New CheckBox

        'cell1
        label1.Text = label
        label1.CssClass = ActivitySettingsPart.LabelCssClass
        cell1.Controls.Add(label1)

        'cell2
        checkbox.ID = ID
        checkbox.CssClass = ActivitySettingsPart.TextBoxCssClass
        checkbox.Checked = defaultValue
        cell2.Controls.Add(checkbox)

        row.Controls.Add(cell1)
        row.Controls.Add(cell2)

        Return row

    End Function

    'create a tablerow that contains a label and textbox
    'Public Function AddTableRowTextBox(ByVal labelText As [String], ByVal controlID As [String], ByVal width _
    '                                    As Integer, ByVal maxLength As Integer, ByVal multiLine As [Boolean], _
    '                                    ByVal defaultValue As [String]) As TableRow

    '    Dim row As New TableRow()
    '    Dim labelCell As New TableCell()
    '    Dim controlCell As New TableCell()
    '    Dim oLabel As New Label()
    '    Dim oText As New TextBox()

    '    oLabel.Text = labelText
    '    oLabel.CssClass = MyBase.LabelCssClass
    '    labelCell.Controls.Add(oLabel)
    '    oText.ID = controlID
    '    oText.CssClass = MyBase.TextBoxCssClass
    '    oText.MaxLength = maxLength
    '    oText.Width = width
    '    'oText.Width = width
    '    oText.Text = defaultValue

    '    If multiLine Then
    '        oText.TextMode = TextBoxMode.MultiLine
    '        oText.Rows = System.Math.Min(6, (maxLength + 60) \ 60)
    '        oText.Wrap = True
    '    End If

    '    controlCell.Controls.Add(oText)
    '    row.Cells.Add(labelCell)
    '    row.Cells.Add(controlCell)

    '    Return row

    'End Function

    'Adds a row with a simple label and text
    'Public Function AddTableRowLabel(ByVal text As String)

    '    Dim row As New TableRow()
    '    Dim labelCell As New TableCell()
    '    Dim oLabel As New Label()

    '    oLabel.Text = text
    '    oLabel.CssClass = MyBase.LabelCssClass
    '    oLabel.Width = Unit.Pixel(400)
    '    labelCell.Controls.Add(oLabel)
    '    row.Cells.Add(labelCell)

    '    Return row

    'End Function

    'Public Function AddNote(ByVal notetitle As String, ByVal noteText As String)

    '    Dim row As New TableRow()
    '    Dim cell1 As New TableCell()
    '    Dim cell2 As New TableCell()
    '    Dim label1 As New Label()
    '    Dim label2 As New Label()

    '    'label1
    '    label1.Text = notetitle
    '    label1.CssClass = MyBase.LabelCssClass
    '    label1.Width = 100
    '    cell1.Controls.Add(label1)

    '    'label2
    '    label2.Text = noteText
    '    label2.CssClass = MyBase.LabelCssClass
    '    cell2.Controls.Add(label2)

    '    row.Cells.Add(cell1)
    '    row.Cells.Add(cell2)

    '    Return row

    'End Function

    Public Function AddDivider()

        Dim dividerRow As New TableRow()
        Dim dividerCell As New TableCell()
        dividerCell.ColumnSpan = 2
        Dim divider As New Literal
        divider.Text = "<hr/>"
        dividerCell.Controls.Add(divider)
        dividerRow.Controls.Add(dividerCell)

        Return dividerRow

    End Function

    Public Function AddCheckBox(ByVal label As String, ByVal id As String, ByVal defaultValue As Boolean)

        Dim row As New TableRow()
        Dim labelCell As New TableCell()
        Dim checkboxCell As New TableCell()
        Dim label1 As New Label()
        Dim checkbox1 As New CheckBox()

        label1.Text = label
        label1.CssClass = ActivitySettingsPart.LabelCssClass
        labelCell.Controls.Add(label1)

        checkbox1.ID = id
        checkbox1.CssClass = ActivitySettingsPart.TextBoxCssClass
        checkbox1.Checked = defaultValue
        checkboxCell.Controls.Add(checkbox1)

        row.Cells.Add(labelCell)
        row.Cells.Add(checkboxCell)

        Return row

    End Function

    'Public Function GetText(ByVal textBoxID As String) As String

    '    Dim textBox As TextBox = DirectCast(Me.FindControl(textBoxID), TextBox)
    '    Return If(textBox.Text, [String].Empty)

    'End Function

    'Public Sub SetText(ByVal textBoxID As String, ByVal text As String)

    '    Dim textBox As TextBox = DirectCast(Me.FindControl(textBoxID), TextBox)
    '    If textBox IsNot Nothing Then
    '        textBox.Text = text
    '    Else
    '        textBox.Text = ""
    '    End If

    'End Sub

    'Public Function getChecked(ByVal checkBoxID As String)

    '    Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)
    '    Return checkBox.Checked

    'End Function

    'Public Sub setChecked(ByVal checkBoxID As String, ByVal value As Boolean)

    '    Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)
    '    If checkBox Is Nothing Then
    '        Return
    '    End If
    '    checkBox.Checked = value

    'End Sub

    'Set the text box to read mode or read/write mode 
    'Public Sub SetTextBoxReadOnlyOption(ByVal textBoxID As String, ByVal [readOnly] As Boolean)

    '    Dim textBox As TextBox = DirectCast(Me.FindControl(textBoxID), TextBox)
    '    textBox.ReadOnly = [readOnly]
    '    'textBox.Enabled = (Not [readOnly])

    'End Sub


End Class
